home *** CD-ROM | disk | FTP | other *** search
/ Mac OS 9 Serial Number Archive / SN Archive 2023.11.04.toast / BSNG / SDK / BSNG SDK 2.5 / BSNG Template / Template.c next >
Encoding:
C/C++ Source or Header  |  1998-02-05  |  9.8 KB  |  356 lines  |  [TEXT/CWIE]

  1. /*
  2.  * $Workfile:: Template.c                                                     $
  3.  * $Revision:: 3                                                              $
  4.  *
  5.  * $Author:: Buck Rogers                                                      $
  6.  * $Modtime:: 29.10.1997 17:52 Uhr                                            $
  7.  *
  8.  * $History:: Template.c                                                      $
  9.  * 
  10.  * *****************  Version 3  *****************
  11.  * User: Buck Rogers  Date: 29.10.1997   Time: 17:53 Uhr
  12.  * Updated in $/BSNG/Plugins/BSNG SDK/BSNG Template
  13.  * updated source to show how to make use of the new 'errorText' variable
  14.  * 
  15.  * *****************  Version 2  *****************
  16.  * User: Buck Rogers  Date: 08.10.1997   Time: 02:02 Uhr
  17.  * Updated in $/BSNG/Plugins/BSNG SDK/BSNG Template
  18.  * changed lf to cr in list generation so Mac compatible output is created
  19.  * 
  20.  * *****************  Version 1  *****************
  21.  * User: Buck Rogers  Date: 06.10.1997   Time: 06:25 Uhr
  22.  * Created in $/BSNG/Plugins/BSNG SDK/BSNG Template
  23.  * Adding subproject 'BSNG Template' to '$/BSNG/Plugins/BSNG SDK'
  24.  * 
  25.  * $NoKeywords::                                                              $
  26.  */
  27.  
  28.  
  29. #include <MixedMode.h>
  30. #include <A4Stuff.h>
  31.  
  32. #include "standard utils.h"
  33. #include "UltraU.h"
  34. #include "BSNG API.h"
  35.  
  36.  
  37. /*    don't touch this __procinfo definition or the calls from native code will crash the machine */
  38.  
  39. ProcInfoType __procinfo = kThinkCStackBased | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(BSNGParamBlockPtr)));
  40.  
  41.  
  42. /*    function prototypes for ANSI C */
  43.  
  44. static void DoInit(BSNGParamBlockPtr inData);
  45. static Boolean DoValidate(BSNGParamBlockPtr inData);
  46. static void DoCalc(BSNGParamBlockPtr inData);
  47. static void DoRandomCalc(BSNGParamBlockPtr inData);
  48. static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData);
  49. static void DoItemHit(BSNGParamBlockPtr inData);
  50. static void DoCleanup(BSNGParamBlockPtr inData);
  51. void main(BSNGParamBlockPtr inData);
  52.  
  53.  
  54. /*    here is where the fun starts :-) */
  55.  
  56. static void DoInit(BSNGParamBlockPtr inData)
  57. {
  58.     StringPtr        item1 = inData->itemValue[kItemValue1];
  59.     StringPtr        item2 = inData->itemValue[kItemValue2];
  60.     StringPtr        item3 = inData->itemValue[kItemValue3];
  61.     StringPtr        item4 = inData->itemValue[kItemValue4];
  62.     StringPtr        item5 = inData->itemValue[kItemValue5];
  63.     StringPtr        item6 = inData->itemValue[kItemValue6];
  64.     StringPtr        item7 = inData->itemValue[kItemValue7];
  65.     StringPtr        item8 = inData->itemValue[kItemValue8];
  66.     StringPtr        item9 = inData->itemValue[kItemValue9];
  67.     StringPtr        item10 = inData->itemValue[kItemValue10];
  68.     
  69.     
  70.     /*    Initialize the Ultra Random Number generator (optional, use MacOS random functions otherwise) */
  71.     
  72.     Ultra_seed1 = inData->randSeed1;
  73.     Ultra_seed2 = inData->randSeed2;
  74.     Ultra_Init();
  75.     
  76.     /*    Give the BSNG App the informations if your plugin can do random calculations and if it can write
  77.         to the serial number list */
  78.     
  79.     inData->wantsRandomButton = true;
  80.     inData->canAddToSNList = true;
  81.     
  82.     /*    Initialize the EditFields with initial default values (optional, they are empty otherwise) */
  83.     /*    if you create a name-based generator please make sure that you copy the name, company and/or numCopies */
  84.     /*    values into the corrosponding fields */
  85.  
  86. /*    not name-based example
  87.     BlockMoveData("\p12345678", item1, 9);
  88.     BlockMoveData("\p23456789", item2, 9);
  89.     BlockMoveData("\p34567890", item3, 9);
  90.     item4[0] = 0;
  91. */
  92.  
  93.  
  94. /*    name-based example
  95.     BlockMoveData(inData->name, item1, inData->name[0] + 1);
  96.     BlockMoveData(inData->company, item2, inData->company[0] + 1);
  97.     BlockMoveData(inData->numCopies, item3, inData->numCopies[0] + 1);
  98.     item4[0] = 0;
  99. */
  100.  
  101.     /*    Tell the BSNG App if the initialisation was successful (it was in our case) */
  102.     
  103.     inData->error = errExtNoErr;
  104.     inData->errorInItem = 0;
  105. }  /* DoInit */
  106.  
  107.  
  108. static Boolean DoValidate(BSNGParamBlockPtr inData)
  109. {
  110.     StringPtr        item1 = inData->itemValue[kItemValue1];
  111.     StringPtr        item2 = inData->itemValue[kItemValue2];
  112.     StringPtr        item3 = inData->itemValue[kItemValue3];
  113.     StringPtr        item4 = inData->itemValue[kItemValue4];
  114.     StringPtr        item5 = inData->itemValue[kItemValue5];
  115.     StringPtr        item6 = inData->itemValue[kItemValue6];
  116.     StringPtr        item7 = inData->itemValue[kItemValue7];
  117.     StringPtr        item8 = inData->itemValue[kItemValue8];
  118.     StringPtr        item9 = inData->itemValue[kItemValue9];
  119.     StringPtr        item10 = inData->itemValue[kItemValue10];
  120.     Boolean            error = false;
  121.     
  122.     
  123.     /*    we do some simple checks here if the edit fields are not empty or not longer than 8 characters, additionally we could
  124.         also check if the values are really only numbers, but I skipped that because the input filter for the edit fileds
  125.         was set to integer anyway (defined in Constructor) */
  126.     
  127.     inData->errorText[0] = 0;
  128.     
  129.     if ((item1[0] < 1) || (item1[0] > 8))
  130.     {
  131.         /*    if something was wrong in the input tell the BSNG App what edit field contained wrong values */
  132.         
  133.         inData->errorInItem = kEditItem1;
  134.         error = true;
  135.         
  136.         /*    build the errorText string here (optional), leave errorText empty if you don't want to use this feature */
  137.         
  138. /*
  139.         myAppendPStr(inData->errorText, "\pEditField 1 contains a wrong value");
  140. */
  141.     }
  142.     else if ((item2[0] < 1) || (item2[0] > 8))
  143.     {
  144.         inData->errorInItem = kEditItem2;
  145.         error = true;
  146.         
  147. /*
  148.         myAppendPStr(inData->errorText, "\pEditField 2 contains a wrong value");
  149. */
  150.     }
  151.     
  152.     if (error)
  153.     {
  154.         inData->error = errExtIncorrectValue;
  155.         return (false);
  156.     }
  157.     
  158.     inData->error = errExtNoErr;
  159.     
  160.     return (true);
  161. }  /* DoValidate */
  162.  
  163.  
  164. static void DoCalc(BSNGParamBlockPtr inData)
  165. {
  166.     StringPtr        item1 = inData->itemValue[kItemValue1];
  167.     StringPtr        item2 = inData->itemValue[kItemValue2];
  168.     StringPtr        item3 = inData->itemValue[kItemValue3];
  169.     StringPtr        item4 = inData->itemValue[kItemValue4];
  170.     StringPtr        item5 = inData->itemValue[kItemValue5];
  171.     StringPtr        item6 = inData->itemValue[kItemValue6];
  172.     StringPtr        item7 = inData->itemValue[kItemValue7];
  173.     StringPtr        item8 = inData->itemValue[kItemValue8];
  174.     StringPtr        item9 = inData->itemValue[kItemValue9];
  175.     StringPtr        item10 = inData->itemValue[kItemValue10];
  176.     
  177.     
  178.     /* do your calculations here */
  179.     
  180.     ZeroScrap();
  181. /*
  182.     PutScrap(result, 'TEXT', &(result[1]));
  183. */
  184. }  /* DoCalc */
  185.  
  186.  
  187. static void DoRandomCalc(BSNGParamBlockPtr inData)
  188. {
  189.     StringPtr        item1 = inData->itemValue[kItemValue1];
  190.     StringPtr        item2 = inData->itemValue[kItemValue2];
  191.     StringPtr        item3 = inData->itemValue[kItemValue3];
  192.     StringPtr        item4 = inData->itemValue[kItemValue4];
  193.     StringPtr        item5 = inData->itemValue[kItemValue5];
  194.     StringPtr        item6 = inData->itemValue[kItemValue6];
  195.     StringPtr        item7 = inData->itemValue[kItemValue7];
  196.     StringPtr        item8 = inData->itemValue[kItemValue8];
  197.     StringPtr        item9 = inData->itemValue[kItemValue9];
  198.     StringPtr        item10 = inData->itemValue[kItemValue10];
  199.     
  200.     
  201.     /*    prepare random calculations here */
  202.     
  203.     DoCalc(inData);
  204. }  /* DoRandomCalc */
  205.  
  206.  
  207. static Boolean DoAddRandomsToList(BSNGParamBlockPtr inData)
  208. {
  209.     StringPtr        item1 = inData->itemValue[kItemValue1];
  210.     StringPtr        item2 = inData->itemValue[kItemValue2];
  211.     StringPtr        item3 = inData->itemValue[kItemValue3];
  212.     StringPtr        item4 = inData->itemValue[kItemValue4];
  213.     StringPtr        item5 = inData->itemValue[kItemValue5];
  214.     StringPtr        item6 = inData->itemValue[kItemValue6];
  215.     StringPtr        item7 = inData->itemValue[kItemValue7];
  216.     StringPtr        item8 = inData->itemValue[kItemValue8];
  217.     StringPtr        item9 = inData->itemValue[kItemValue9];
  218.     StringPtr        item10 = inData->itemValue[kItemValue10];
  219.         
  220.     long            count = 0L;
  221.     short            i = 0;
  222.     OSErr            err = noErr;
  223.     
  224.     
  225.     /*    write your header to the number list */
  226.     
  227.     count = 24L;
  228.     err = FSWrite(inData->outputRefNum, &count, "<Your plugin name here>\r");
  229.     
  230.     /*    return false if an error occured, the creation of list will then be completly aborted */
  231.     
  232.     if (err != noErr)
  233.     {
  234.         return (false);
  235.     }
  236.     
  237.     count = 24L;
  238.     err = FSWrite(inData->outputRefNum, &count, "=======================\r");
  239.     
  240.     if (err != noErr)
  241.     {
  242.         return (false);
  243.     }
  244.     
  245.     /*    create numOfListNumbers random serial numbers and write them to the list */
  246.     /*    if you create a name-based generator please make sure that you create at least one number */
  247.     /*    using the name, company and/or numCopies informations. You could create more name-based numbers */
  248.     /*    by using your own name/company database */
  249.     
  250.     for (i = 0; i < inData->numOfListNumbers; i++)
  251.     {
  252.         DoRandomCalc(inData);
  253.         
  254.         /* write results to list here */
  255.     }
  256.     
  257.     /* don't forget this last newline */
  258.     
  259.     count = 1L;
  260.     err = FSWrite(inData->outputRefNum, &count, "\r");
  261.     
  262.     if (err != noErr)
  263.     {
  264.         return (false);
  265.     }
  266.     
  267.     return (true);
  268. }  /* DoAddRandomsToList */
  269.  
  270.  
  271. static void DoItemHit(BSNGParamBlockPtr inData)
  272. {
  273.     switch (inData->itemMessage)
  274.     {
  275.         case (300000):
  276.         
  277.             /*    the "About this plugin" button was pressed, do whatever you want, I just display a small Alert here */
  278.         
  279.             NoteAlert(1000, nil);
  280.             break;
  281.         
  282.         default:
  283.             break;
  284.     }
  285. }  /* DoItemHit */
  286.  
  287.  
  288. static void DoCleanup(BSNGParamBlockPtr inData)
  289. {
  290. #pragma unused (inData)
  291.  
  292.     /*    we didn't allocate any memory in DoInit, so we can leave this empty, otherwise it would be a VERY good idea
  293.         to deallocate/dispose etc. everything we allocated during our work. If you don't do that we have a nice memory leak */
  294.     
  295. }  /* DoCleanup */
  296.  
  297.  
  298. void main(BSNGParamBlockPtr inData)
  299. {
  300. #if (!GENERATINGPOWERPC)
  301.     EnterCodeResource();
  302. #endif
  303.     
  304.     /*    the message dispatcher */
  305.     
  306.     switch(inData->theMessage)
  307.     {
  308.         case (msgExtInit):
  309.             DoInit(inData);
  310.             break;
  311.         
  312.         case (msgExtCalcHit):
  313.         
  314.             if (DoValidate(inData))
  315.             {
  316.                 DoCalc(inData);
  317.             }
  318.             
  319.             break;
  320.         
  321.         case (msgExtRandomHit):
  322.             DoRandomCalc(inData);
  323.             break;
  324.         
  325.         case (msgExtCreateRandom):
  326.             
  327.             /*    report to the BSNG App if your list entry was written ok or if we had an error */
  328.             
  329.             if (DoAddRandomsToList(inData))
  330.             {
  331.                 inData->error = errExtNoErr;
  332.             }
  333.             else
  334.             {
  335.                 inData->error = errExtWritingToList;
  336.             }
  337.             
  338.             break;
  339.         
  340.         case (msgExtItemHit):
  341.             DoItemHit(inData);
  342.             break;
  343.         
  344.         case (msgExtCleanup):
  345.             DoCleanup(inData);
  346.             break;
  347.         
  348.         default:
  349.             break;
  350.     }
  351.     
  352. #if (!GENERATINGPOWERPC)
  353.     ExitCodeResource();
  354. #endif
  355. }  /* main */
  356.